//
//  HWMenuView.m
//  嗨文
//
//  Created by 响当当 on 5/15/19.
//  Copyright © 2019 dongzheng. All rights reserved.
//

#import "HWMenuView.h"

@interface HWMenuView()
@property (nonatomic, copy)NSArray *titleArr;
@property (nonatomic, copy)NSArray *imageArr;
@property (nonatomic, assign)BOOL turnOrClose;
@end

@implementation HWMenuView


- (NSArray *)titleArr
{
    if (!_titleArr)
    {
        _titleArr = @[@"上一章",@"目录",@"设置",@"关灯",@"下一章"];
    }
    return _titleArr;
}

- (NSArray *)imageArr
{
    if (!_imageArr)
    {
        _imageArr = @[@"up",@"index",@"setting",@"moon",@"next"];
    }
    return _imageArr;
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self)
    {
        UIView *lineView = [[UIView alloc]initWithFrame:CGRectMake(0,0,SCREEN_WIDTH,1*kUIScaleBasePlus)];
        lineView.backgroundColor = JSALineColor;
        [self addSubview:lineView];
        
        [self creatUI];
        self.turnOrClose = NO;
    }
    return self;
}

- (void)creatUI
{
    CGFloat width = SCREEN_WIDTH/5;
    CGFloat height = TABBAR_HEIGHT+20*kUIScaleBasePlus;
    
    for (int i=0;i < self.titleArr.count; i++)
    {
        UIButton *button = [HWUtilties creatButtonWithFrame:CGRectMake(i*width,IS_INCH_X ? -18*kUIScaleBasePlus : -5*kUIScaleBasePlus,width,height)
                                               textAligment:NSTextAlignmentCenter
                                                       text:self.titleArr[i]
                                                   textClor:[UIColor blackColor]
                                                  buttonBGC:[UIColor clearColor]
                                                   textFont:14*kUIScaleBasePlus
                                                     target:self
                                                     method:@selector(btnClick:)];
        button.tag = i;
        [button setImage:[UIImage imageNamed:self.imageArr[i]] forState:UIControlStateNormal];
        [button setUpImageAndDownLableWithSpace:6];

        
        
        [self addSubview:button];
        
    }
}

- (void)btnClick:(UIButton *)sender
{
    if (self.getMenuClickBlock)
    {
        self.getMenuClickBlock([NSString stringWithFormat:@"%ld",sender.tag]);
    }
    
    if (sender.tag == 3)
    {
        if (self.turnOrClose)
        {
            [sender setImage:[UIImage imageNamed:@"moon"] forState:UIControlStateNormal];
            self.turnOrClose = NO;
        }
        else
        {
            [sender setImage:[UIImage imageNamed:@"sun"] forState:UIControlStateNormal];
            self.turnOrClose = YES;
        }
        
        if (self.turnOrCloseLightBlock)
        {
            self.turnOrCloseLightBlock(self.turnOrClose);
        }
    }
    
}


@end
